<template>
  <div class="login-container">
    <el-form :model="form" >
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password"></el-input>
      </el-form-item>
      <el-form-item align="center">
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods:{
    login(){
      this.$http.post('api/permission/getMenu', this.form).then(res => {
        res = res.data
        console.log(res.data)
        if (res.code === 20000) {
          this.$store.commit('clearMenu')
          this.$store.commit('setMenu', res.data.menu)
          this.$store.commit('setToken', res.data.token)
          this.$store.commit('addMenu', this.$router)
          console.log(this.$router)
          console.log(res.data.menu)
          this.$router.push({ name: 'home' })
        } else {
          this.$message.warning(res.data.message)
        }
      })
      // let username=this.form.username;
      // if(username==='admin'){
      //   this.$store.commit("setToken",username);
      //   this.$router.addRoute({name:'home'});
      // }
    }
  }
}
</script>

<style scoped>
.login-container{
  display: flex;
  display: -webkit-flex;
  justify-content: center;
  height: 100vh;
}
.el-form{
  margin: auto;
  width: 400px;
  justify-content: center;
}
</style>